#include <stdio.h>
#include <stdlib.h>

typedef int TElemSet;

typedef struct BinaryTreeNode *BinaryTree;
struct BinaryTreeNode {
    TElemSet data; /* 数据元素 */
    BinaryTree left; /* 左孩子指针 */
    BinaryTree right; /* 右孩子指针 */
};

/* 链式堆栈定义 */
typedef enum {false, true} bool;
#define NIL NULL
typedef BinaryTree SElemSet;

typedef struct StackNode *Position; /* 指针即结点位置 */
struct StackNode {
    SElemSet data; /* 存储数据 */
    Position next; /* 链接栈中下一个元素的位置 */
};
typedef struct StackHeadNode *Stack;
struct StackHeadNode {
    int size; /* 链接栈中当前元素个数 */
    Position top; /* 链接栈的栈顶指针，初始化为NULL */
};

void InitStack(Stack stack) {
    /* 初始化一个空的链接栈 */
    stack->size = 0;
    stack->top = NULL;
}

bool IsEmpty(Stack stack) {
    /* 判断栈是否为空 */
    if (stack->size == 0)
        return true;
    else
        return false;
}

void Push(Stack stack, SElemSet x) {
    Position new_node;

    new_node = (Position)malloc(sizeof(struct StackNode));
    new_node->data = x;
    new_node->next = stack->top;
    stack->top = new_node;
    stack->size++;
}

SElemSet Top(Stack stack) {
    if (IsEmpty(stack)) {
        printf("错误：栈为空。\n");
        return NIL;
    } else {
        return stack->top->data;
    }
}

void Pop(Stack stack) {
    Position temp;

    if (IsEmpty(stack)) {
        printf("错误：栈为空。\n");
    } else {
        temp = stack->top;
        stack->top = stack->top->next;
        free(temp);
        stack->size--;
    }
}

void DestroyStack(Stack stack) {
    free(stack);
}
/* 堆栈定义结束*/

BinaryTree CreateBinaryTree(TElemSet value, BinaryTree left_tree,
                            BinaryTree right_tree) {
    BinaryTree tree;

    tree = (BinaryTree)malloc(sizeof(struct BinaryTreeNode));
    tree->data = value;
    tree->left = left_tree;
    tree->right = right_tree;
    return tree;
}

void Visit(BinaryTree tree) {
    printf("%d\n", tree->data);
}

/* 算法5-7：非递归前序遍历二叉树 PreOrder(tree) */
void PreOrder(BinaryTree tree) {
    Stack stack;

    stack = (Stack)malloc(sizeof(struct StackHeadNode));
    InitStack(stack); /* 初始化栈stack，用于存放结点 */
    while (tree != NULL || IsEmpty(stack) == false) {
        while (tree != NULL) { /* 当前结点不是空结点 */
            Visit(tree); /* 访问结点 */
            Push(stack, tree); /* 结点压入栈 */
            tree = tree->left; /* 沿左分支下移 */
        }
        if (IsEmpty(stack) == false) { /* 如果栈不为空 */
            tree = Top(stack);
            Pop(stack); /* 弹出栈顶结点 */
            tree = tree->right; /* 移到右子树 */
        }
    }
    DestroyStack(stack);
}
/* 算法5-7 结束 */

int main(void) {
    BinaryTree tree, left_tree, right_tree;
    TElemSet value;

    scanf("%d", &value);
    left_tree = CreateBinaryTree(value, NULL, NULL);
    scanf("%d", &value);
    right_tree = CreateBinaryTree(value, NULL, NULL);
    scanf("%d", &value);
    tree = CreateBinaryTree(value, left_tree, right_tree);
    PreOrder(tree);

    return 0;
}